package tio.study.helloworld.client;

import org.tio.client.intf.ClientAioHandler;
import org.tio.core.ChannelContext;

import tio.study.helloworld.common.AbsHandler;
import tio.study.helloworld.common.HelloPacket;

/**
 * 客户端handler类
 * @author Administrator
 *
 */
public class ClientHandler extends AbsHandler implements ClientAioHandler<Object,HelloPacket,Object>{

	/**
	 * 消息处理
	 */
	@Override
	public Object handler(HelloPacket packet, ChannelContext<Object, HelloPacket, Object> channelContext)
			throws Exception {
		byte[] body = packet.getBody();
		if(body != null){
			String str = new String(body,HelloPacket.CHARSET);
			System.out.println("客户端收到的信息是："+str);
		}
		return null;
	}
	
	private static HelloPacket heartbeatPacket = new HelloPacket();
	/**
	 * 发送心跳包
	 */
	@Override
	public HelloPacket heartbeatPacket() {
		
		return heartbeatPacket;
	}

}
